package it.polimi.traveldream.ejb.entities;

import it.polimi.traveldream.ejbclient.dtos.ParticipationDTO;

import java.io.Serializable;

import javax.persistence.*;

import java.sql.Timestamp;
import java.util.Date;


/**
 * The persistent class for the participation database table.
 * 
 */
@Entity
@NamedQueries({
	@NamedQuery(name=Participation.FIND_PARTICIPATIONS,
			query="SELECT p FROM Participation p WHERE p.travelpackage.overpast = :overpast ORDER BY p.timestamp ASC"),
	@NamedQuery(name=Participation.FIND_USER_PARTICIPATIONS,
			query="SELECT p FROM Participation p WHERE p.id.customer = :customerId AND p.travelpackage.overpast = :overpast ORDER BY p.timestamp ASC"),
	@NamedQuery(name=Participation.FIND_PARTICIPATIONS_BY_PACKAGE,
			query="SELECT p FROM Participation p WHERE p.id.travelPackage = :packageId AND p.travelpackage.overpast = :overpast ORDER BY p.timestamp ASC")

})
public class Participation implements Serializable {
	private static final long serialVersionUID = 1724898968869976084L;
	public static final String FIND_PARTICIPATIONS = "Participation.findParticipations";
	public static final String FIND_USER_PARTICIPATIONS = "Participation.findUserParticipations";
	public static final String FIND_PARTICIPATIONS_BY_PACKAGE = "Participation.findParticipationsByPackage";
	private ParticipationPK id;
	private int reservations;
	private Timestamp timestamp;
	private Travelpackage travelpackage;
	private User user;

	public Participation() {
		super();
	}

	public Participation(ParticipationDTO participation) {
		super();
		this.reservations = participation.getReservations();
		this.timestamp = new Timestamp(new Date().getTime());
		this.travelpackage = new Travelpackage(participation.getTravelpackage());
		this.user = new User(participation.getUser());
	}


	@EmbeddedId
	public ParticipationPK getId() {
		return this.id;
	}

	public void setId(ParticipationPK id) {
		this.id = id;
	}


	public int getReservations() {
		return this.reservations;
	}

	public void setReservations(int reservations) {
		this.reservations = reservations;
	}


	public Timestamp getTimestamp() {
		return this.timestamp;
	}

	public void setTimestamp(Timestamp timestamp) {
		this.timestamp = timestamp;
	}


	//bi-directional many-to-one association to Travelpackage
	@ManyToOne
	@JoinColumn(name="TravelPackage")
	public Travelpackage getTravelpackage() {
		return this.travelpackage;
	}

	public void setTravelpackage(Travelpackage travelpackage) {
		this.travelpackage = travelpackage;
	}


	//bi-directional many-to-one association to User
	@ManyToOne
	@JoinColumn(name="Customer")
	public User getUser() {
		return this.user;
	}

	public void setUser(User user) {
		this.user = user;
	}

}